package org.ceteca.explica.server.management;

import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.util.ArrayList;
import java.util.List;

import org.ceteca.explica.core.ExplicaException;
import org.ceteca.explica.core.common.BaseVO;
import org.ceteca.explica.core.management.DocumentLineOT;
import org.ceteca.explica.core.management.DocumentOT;
import org.ceteca.explica.core.management.ManagementManager;
import org.ceteca.explica.core.management.MovementOT;
import org.ceteca.explica.core.management.SerialNumberOT;
import org.ceteca.explica.core.util.OperationResult;
import org.ceteca.explica.server.common.bl.CommonBLL;
import org.ceteca.explica.server.management.bl.ManagementBLL;
import org.ceteca.explica.server.util.db.CriteriaBean;
import org.ceteca.explica.core.util.FieldValue;
import org.ceteca.explica.core.warehouse.ProductOT;
import org.ceteca.explica.core.warehouse.StockOT;
import org.ceteca.explica.core.warehouse.WarehouseOT;
import org.ceteca.explica.server.util.db.InterfaceDB;




/**
 * @author Juan C. Díaz (juancarlosdiaz@ceteca.net) <br>
 *         Copyright (c) 2009 Fundación Centro Tecnolóxico da Carne
 * 
 * <br>
 * <br>
 *         This program is free software: you can redistribute it and/or modify
 *         it under the terms of the GNU General Public License as published by
 *         the Free Software Foundation, either version 3 of the License, or (at
 *         your option) any later version. <br/>
 *         This program is distributed in the hope that it will be useful, but
 *         WITHOUT ANY WARRANTY 
 *         <br>without even the implied warranty of
 *         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 *         General Public License for more details. <br/>
 *         You should have received a copy of the GNU General Public License
 *         along with this program. If not, see <http://www.gnu.org/licenses/>.
 * 
 */
public class ManagementManagerImpl extends UnicastRemoteObject implements
		ManagementManager {
	private static final long serialVersionUID = 123456789;

	public ManagementManagerImpl() throws RemoteException {
		super();
	}

	





	public long nextSerialNumber(SerialNumberOT serial) throws RemoteException,ExplicaException{
		
		
		return ManagementBLL.getInstance().nextSerialNumber(serial);
		

	}







	@Override
	public ArrayList<StockOT> getProductStock(ProductOT product,
			WarehouseOT warehouse) throws ExplicaException, RemoteException {
		return ManagementBLL.getInstance().getProductStock(product, warehouse);
	}







	@Override
	public OperationResult deleteMovements(DocumentLineOT entityData)
			throws RemoteException, ExplicaException {
//		ArrayList<CriteriaBean > lCriteria=new ArrayList<CriteriaBean>();
//		lCriteria.add(this.buildCriteria("documentLine", entityData));
//		return ManagementBLL.getInstance().delEntities(lCriteria, MovementOT.class);
		
		return null;
	}

	private CriteriaBean buildCriteria(String fieldId, Object value) {
		CriteriaBean result = null;
		Object val = null;
		String op;

		if (value instanceof String) {
			op = InterfaceDB.SQL_OPERATOR_LIKE;
			val = new String("%" + value + "%");
		} else {
			op = InterfaceDB.SQL_OPERATOR_EQUAL;
			val = value;
		}

		// Add the query criteria to the list
		if (fieldId != null && fieldId.length() > 0 && val != null) {
			result = new CriteriaBean(fieldId, val, op, InterfaceDB.LOGIC_OPERATOR_AND, null, null);
		}

		return result;
	}


}
